/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwbillmanager.                                    *
 *                                                                           *
 *   niwbillmanager is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwbillmanager is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwbillmanager. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#include "settingsdialog.h"

SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
{
    setupUi(this);
}

QColor SettingsDialog::getDuePastColor()
{
    return duePastColor->getColor();
}

QColor SettingsDialog::getDueTodayColor()
{
    return dueTodayColor->getColor();
}

QString SettingsDialog::getCurrencySymbol()
{
    return currencyEdit->text();
}

QString SettingsDialog::getSelectedBackendName()
{
    QString selectedBackend = "";
    if (!backendList->selectedItems().isEmpty()) {
        selectedBackend = backendList->selectedItems().first()->text(0);
    }

    return selectedBackend;
}

void SettingsDialog::setDuePastColor(QColor color)
{
    duePastColor->setColor(color);
}

void SettingsDialog::setDueTodayColor(QColor color)
{
    dueTodayColor->setColor(color);
}

void SettingsDialog::setCurrencySymbol(QString symbol)
{
    currencyEdit->setText(symbol);
}

void SettingsDialog::setBackends(const QHash<QString, Backend *> &backends,
    const QString &selectedName)
{
    Q_FOREACH (Backend *backend, backends) {
        QStringList columns;
        QString toolTip;

        columns << backend->getName() << backend->getDescription()
            << (backend->isRemote()?"True":"False") << backend->getVersion();
        toolTip = backend->getName() + " - " + backend->getVersion()
            + " / " + (backend->isRemote()?"Remote":"Not Remote") + "\n\n"
            + backend->getDescription();

        QTreeWidgetItem *insertItem = new QTreeWidgetItem(columns);
        backendList->insertTopLevelItem(0, insertItem);

        // Set the tool tip for every column
        for (int i = 0; i < columns.size(); i++) {
            insertItem->setToolTip(i, toolTip);
        }

        if (backend->getName() == selectedName) {
            insertItem->setSelected(true);
            backendList->setCurrentItem(insertItem);
        }

        backendList->sortItems(0, Qt::AscendingOrder);
    }
}
